import {
	IsNotEmpty,
	IsString,
	IsEnum,
	IsNumber,
	Min,
	IsOptional,
	IsIn,
} from "class-validator";
import { ApiProperty } from "@nestjs/swagger";

export class CreateProductDto {
	@ApiProperty({ description: "商品名称", example: "积分兑换券" })
	@IsNotEmpty({ message: "商品名称不能为空" })
	@IsString({ message: "商品名称必须是字符串" })
	name: string;

	@ApiProperty({
		description: "商品分类",
		enum: ["数码", "食品", "服装", "家居"],
		example: "数码",
	})
	@IsNotEmpty({ message: "商品分类不能为空" })
	@IsIn(["数码", "食品", "服装", "家居"], {
		message: "商品分类必须是数码、食品、服装、家居之一",
	})
	category: string;

	@ApiProperty({ description: "商品价格（积分）", example: 100 })
	@IsNotEmpty({ message: "商品价格不能为空" })
	@IsNumber({}, { message: "商品价格必须是数字" })
	@Min(0, { message: "商品价格不能小于0" })
	price: number;

	@ApiProperty({ description: "商品库存", example: 50 })
	@IsNotEmpty({ message: "商品库存不能为空" })
	@IsNumber({}, { message: "商品库存必须是数字" })
	@Min(0, { message: "商品库存不能小于0" })
	stock: number;

	@ApiProperty({
		description: "商品状态",
		enum: ["在售", "已下架"],
		example: "在售",
	})
	@IsNotEmpty({ message: "商品状态不能为空" })
	@IsIn(["在售", "已下架"], { message: "商品状态必须是在售或已下架" })
	status: string;

	@ApiProperty({
		description: "商品图片",
		required: false,
		example: "https://example.com/image.jpg",
	})
	@IsOptional()
	@IsString({ message: "商品图片必须是字符串" })
	image: string;

	@ApiProperty({
		description: "商品图片URL（前端上传时使用）",
		required: false,
	})
	@IsOptional()
	@IsString({ message: "商品图片URL必须是字符串" })
	imageUrl?: string;

	@ApiProperty({
		description: "商品描述",
		required: false,
		example: "这是一个积分兑换券，可以用于兑换商品",
	})
	@IsOptional()
	@IsString({ message: "商品描述必须是字符串" })
	description: string;
}
